<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录</title>
<link rel="stylesheet" type="text/css" href="common/ext-4.0/resources/css/ext-all.css" />
<script type="text/javascript" src="common/ext-4.0/ext-all.js"></script>
<script type="text/javascript" src="common/js/MyExt.js"></script>
<script type="text/javascript" src="common/ext-4.0/locale/ext-lang-zh_CN.js"></script>

<script type="text/javascript">
Ext.onReady(function() {
	//取得cookie
	Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	
	//创建登录的panel
	var form = Ext.create('Ext.form.Panel',{
		labelWidth: 40,
        border: false,
        buttonAlign: 'center',
        style: 'border-bottom:0px;',
        bodyStyle: 'padding:10px;background-color:transparent;',
        url: '#',
        items:[
	            
            	   {// 账号
        	xtype:'textfield',
    				inputType: 'textfiled',
            id: 'username',
            name: 'user.account',
            fieldLabel: '账号',
            anchor:'98%',
            allowBlank:false,
            maxLength: 20,
           	listeners:{
				specialKey:function(field, e){
					if(e.getKey() == Ext.EventObject.ENTER){
						Ext.getCmp("login-button").handler();
					}
				}
           	}
       },{// 密码
    	   xtype:'textfield',
    	   inputType: 'password',
           id:'password',
           name:'user.password',
           fieldLabel:'密码',
           anchor:'98%',
           allowBlank:false,
           maxLength: 20,
           listeners:{
				specialKey:function(field, e){
					if(e.getKey() == Ext.EventObject.ENTER){
						Ext.getCmp("login-button").handler();
					}
				}
           }
	},{
           xtype: 'checkboxgroup',
           itemCls: 'x-check-group-alt',
           columns: 3,
           items: [
               {boxLabel: '记住账号', name: 'rememberUserId',
            	   listeners: {
            	   		check: function(){
							if(!this.getValue()){
								var f = form.getForm();
								f.findField('autoLogin').setValue(false);
							}
						}
            	   }
               },
               {boxLabel: '记住密码', name: 'rememberPwd',
            	   listeners: {
            	   		check: function(){
							if(!this.getValue()){
								var f = form.getForm();
								f.findField('autoLogin').setValue(false);
							}
						}
            	   }
               },
               {boxLabel: '自动登录', name: 'autoLogin',
            	   listeners: {
            	   		check: function(){
							if(this.getValue()){
								var f = form.getForm();
								f.findField('rememberUserId').setValue(true);
								f.findField('rememberPwd').setValue(true);
							}
						}
            	   }
               }
           ]
       }],
       buttons: [{
			id:'login-button',
          text:'登录',
          handler: function(){
        	 
          	var f=form.getForm();
         // 发送请求
       var userId = f.findField("username").getValue();
       var password = f.findField("password").getValue();
			MyExt.ajaxRequest({
				baseUrl: 'servlet',
				baseParams: f.getValues(),
				action: '/user.login',
				callback: function(jsonResult){
					
				
					// 设置Cookie
					var rememberUserId = f.findField('rememberUserId').getValue();
					var rememberPwd = f.findField('rememberPwd').getValue();
					var autoLogin = f.findField('autoLogin').getValue();
					
					if(rememberUserId){
						
						Ext.state.Manager.set('Mynote_userId', userId);
						
					}else{
						Ext.state.Manager.set('Mynote_userId', '');
					}
					if(rememberPwd){
						Ext.state.Manager.set('Mynote_password', password);
					}else{
						Ext.state.Manager.set('Mynote_password', '');
					}
					if(autoLogin)
					{
						Ext.state.Manager.set('Mynote_userId', userId);
						Ext.state.Manager.set('Mynote_password', password);
						Ext.state.Manager.set('Mynote_autoLogin', autoLogin);
					}else{
						Ext.state.Manager.set('Mynote_autoLogin', autoLogin);
						}
					
					//Ext.state.Manager.set('Mynote_hasLocked', false);
					Ext.Msg.wait("正在登录，请稍等...","","");
					location.href="admin/index.html";
				},
				showWaiting: true
			});

      	}
      },{
          text: '取消',
          handler: function(){
      		form.getForm().reset();
          }
      }]
	});
	
	  // 状态栏HTMl
   // var bbarHtml = "<a href='javascript:resetPwd();'>忘记密码？</a>";
	
	//bbarHtml = bbarHtml + "&nbsp;&nbsp;<a href='javascript:register();'>注册</a>";
	
	var win = Ext.create('Ext.window.Window', {
        title: '用户登录',
        width: 300,
        height:180,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        closable: false,
        resizable:false,
        plain: true,
        items: form,
        bbar: new Ext.Panel({
			//html: bbarHtml,
			border: false,
			bodyStyle: 'background-color:transparent;padding:3px 10px;'
		})
    });

    win.show();
    
 

	// 根据cookie初期化form
    function initLoginForm(){
    	
    	// 取得cookie
		var cookieUserId = Ext.state.Manager.get('Mynote_userId');
		var cookiePwd = Ext.state.Manager.get('Mynote_password');
		var cookieAutoLogin = Ext.state.Manager.get('Mynote_autoLogin');
		var f = form.getForm();
		// 账号
		
		if(cookieUserId && cookieUserId!=''){
			f.findField('username').setValue(cookieUserId);
			f.findField('rememberUserId').setValue(true);
		}
		// 密码
		if(cookiePwd && cookiePwd!=''){
			f.findField('password').setValue(cookiePwd);
			f.findField('rememberPwd').setValue(true);
		}
		// 自动登录
		f.findField('autoLogin').setValue(cookieAutoLogin);
		if(cookieAutoLogin==true){
			Ext.getCmp("login-button").handler();
		}
	}
	
 // 根据cookie初期化form
	initLoginForm();
 // 忘记密码
	function resetPwd(){
		// 转到登录页面
		location.href="resetPwd.jsp";
	}
	// 注册
	function register(){
		// 转到登录页面
		location.href="register.jsp";
	}

});
</script>

</head>
<body class="x-border-layout-ct" >

<div align="center">


</div>

</body>

</html>